from opt.solver import Solver, Plugin


class TreeExhausted(Plugin):
    signal_map = {Solver.SIGNALS.ITERATION_FINISHED: "check"}

    def check(self):
        """True if the root node has been completely expanded and its children have been fully
        explored. The search is finished when this condition is true."""
        if self.solver.root.is_exhausted():
            self.solver.interrupts.add("root node exhausted", self.solver.ACTION.FINISH)
            if self.solver.solutions.feas_count > 0:
                self.solver.termination = self.solver.TERMINATION.OPTIMAL
            else:
                self.solver.termination = self.solver.TERMINATION.INFEASIBLE
